<template>
  <div v-if="loading">
  <SkeletonLoader/>
</div>
<div v-else>
    <div class="header">
        <div class="header-left">
            湖北武汉
            <van-icon name="arrow" />
        </div>
        <van-search
            v-model="value"
            placeholder="请输入搜索关键词"
            shape="round"
        />
    </div>
    <van-notice-bar
  left-icon="volume-o"
  scrollable 
  text="安康同行，守护您的就医之路。"
/>
    <van-swipe class="my-swiper" height="170" :autoplay="3000" indicator-color="white">
        <van-swipe-item
            v-for="item in homeData.slides"
            :key="item.id"
        >
            <van-image
               radius="5"
              :src="item.pic_image_url"
            />
    </van-swipe-item>
    </van-swipe>
    <van-grid>
      <van-grid-item 
      v-for="(item,index) in homeData.navs"
      :key="item.id"
      @click="goAppoint(item)"
      >
        <van-image
          :src="item.pic_image_url"
        />
        <span>{{ item.title }}</span>
      </van-grid-item>
    </van-grid>
    <van-row justify="space-around">
      <van-col
       span="11"
       v-for="(item,index) in homeData.nav2s"
       :key="item.id"
       class="center-img"
       @click="goOrderTwo(index)"
       >
       <van-image
              :src="item.pic_image_url"
            />
    </van-col>
    </van-row>
    <van-row @click="goOrder(item)" class="yy-list" v-for="item in homeData.hospitals" justify="space-around">
        <van-col span="6">
            <van-image
              :src="item.avatar_url"
              width="100"
              height="90"
            />
        </van-col>
       <van-col class="yy" span="15">
        <div class="yy-name">{{ item.name }}</div>
        <div class="yy-type">
            <span>{{ item.rank }}</span>
            &nbsp;
            <span>{{ item.label }}</span>
        </div>
        <div class="yy-text">{{ item.intro }}</div>
       </van-col>
    </van-row>
  </div>
</template>


<script setup>
import SkeletonLoader from '../../components/skeleton.vue'
import { ref,onMounted,getCurrentInstance,reactive } from 'vue';
import {useRouter} from 'vue-router'
const router = useRouter()
//获取当前vue实例
const {proxy} = getCurrentInstance()
const searchValue = ref('')
const loading = ref(true);
//首页数据
const homeData = reactive({
    hospitals:[],
    nav2s:[],
    navs:[],
    now:'',
    slides:[]
})
//图片快捷入口
const goOrderTwo =()=>{
  router.push(`/createOrder`)
}
onMounted(async()=>{
    const {data} =await proxy.$api.index()
    Object.assign(homeData,data.data)
    homeData.navs = data.data.navs.splice(0,4)
     // 数据加载完成后关闭骨架屏
  loading.value = false;
})
//点击医院列表
const goOrder = (data)=>{
  // console.log(data);
  router.push(`/createOrder?id=${data.id}&name=${data.name}`)
}
//跳转到指定的服务页面
const goAppoint=(item)=>{
  // console.log(item);
  if(item.title === '送取结果'){
    router.push(`/order`)
  }else{
    router.push(`/appointOrder?id=${item.id}&name=${item.title}`)
  }
}
</script>

<style lang="less" scoped>
.header {
    display: flex;
    justify-content: space-between;
    margin: 5px;
    line-height: 54px;
    .header-left {
      padding-left: 22px;
      background: url()
        no-repeat left center;
      background-size: 20px;
      font-size: 20px;
      font-weight: bold;
      color: #666666;
    }
  }
  .my-swiper {
    margin: 5px;
  }
  .yy-list {
    padding-bottom: 10px;
    margin: 20px 0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.04), 0 1px 6px 0 rgba(0, 0, 0, 0.04);
    .yy {
      .yy-name {
        font-size: 20px;
        line-height: 30px;
        font-weight: bold;
      }
      .yy-type {
        font-weight: bold;
        line-height: 25px;
        font-size: 15px;
        color: #0ca7ae;
      }
      .yy-text {
        font-size: 14px;
        color: #999999;
      }
    }
  }
  .bottom-text {
    line-height: 50px;
    text-align: center;
    color: #999999;
  }

</style>